package com.wangsd.web.coupon.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.MyController;
import com.wangsd.web.coupon.entity.ActivityProduct;
import com.wangsd.web.coupon.service.ActivityProductService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-10-23
 */
@Api(value = "限时抢购", tags = "限时抢购")
@RestController
@RequestMapping("/coupon/activityProduct")
public class ActivityProductController extends MyController {
    @Autowired
    ActivityProductService activityProductService;

    @ApiOperation(value = "通过id查询限时抢购", notes = "通过id查询限时抢购", httpMethod = "GET")
    @GetMapping("/select/{id}")
    public Result select(@PathVariable Long id) {
        ActivityProduct newGift = activityProductService.getById(id);
        return Result.success(newGift);
    }

    @ApiOperation(value = "查看限时抢购列表分页", notes = "查看限时抢购列表分页", httpMethod = "POST")
    @PostMapping("/selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             @RequestBody ActivityProduct query) {
        SysUser userInfo = getUserInfo();
        IPage<ActivityProduct> bigWheelIPage = activityProductService.selectPage(userInfo.getCode(), pageNum, pageSize, query);
        return Result.success(bigWheelIPage);
    }

    @ApiOperation(value = "添加修改", notes = "添加修改", httpMethod = "POST")
    @PostMapping("/addOrUpdate")
    public Result addOrUpdate(@RequestBody ActivityProduct entity) {
        activityProductService.addOrUpdate(entity);
        return Result.success();
    }

    @ApiOperation(value = "删除", notes = "删除", httpMethod = "GET")
    @GetMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        activityProductService.removeById(id);
        return Result.success();
    }

    @ApiOperation(value = "上下架", notes = "上下架", httpMethod = "POST")
    @PostMapping("/upActivity")
    public Result upActivity(@RequestBody ActivityProduct activityProduct) {
        activityProductService.upActivity(activityProduct);
        return Result.success();
    }

    @ApiOperation(value = "通过商圈id查询限时抢购List", notes = "通过商圈id查询限时抢购List", httpMethod = "GET")
    @GetMapping("/selectActivityProductByCompanyId/{id}")
    public Result selectActivityProductByCompanyId(@PathVariable Long id) {
        List<String> productIds = activityProductService.selectActivityProductByCompanyId(id);
        return Result.success(productIds);
    }
}

